package mashibing.class1;

import util.MathUtil;

/**
 * 选择排序
 *
 * @author yujiafan
 * @version 1.0.0
 * @create 2023-03-02
 */
public class Class1_1_SelectionSorted {

    public static void selectSort(int[] arr) {
        if (arr == null || arr.length <= 1) {
            return;
        }
        for (int i = 0; i < arr.length - 1; i++) {
            int minIndex = i;
            for (int j = i + 1; j < arr.length; j++) {
                if (arr[minIndex] > arr[j]) minIndex = j;
            }
            MathUtil.swap(arr, minIndex, i);
        }
    }
}
